package open.tech.dawn.web.core.support;

import open.tech.dawn.web.core.properties.JwtProperties;
import open.tech.dawn.web.util.ToolUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class HeaderRequestWrapper extends HttpServletRequestWrapper {

    public HeaderRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getHeader(String name) {
        String header = super.getHeader(name);
        if (JwtProperties.REQUEST_HEADER.equals(name)) {
            if (ToolUtil.isNotEmpty(header) && header.startsWith(JwtProperties.HEADER_BODY_PREFIX)) {
                return header.substring(JwtProperties.HEADER_BODY_PREFIX.length()).trim();
            }
        }
        return header;
    }
}
